<?php
ini_set('default_charset','utf-8');

include_once $_SERVER['DOCUMENT_ROOT'].'/lib/share.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/lib/jApi.php';

$API=jApi::inst( $_SERVER['DOCUMENT_ROOT'].'/conf/japi.usr.php' );
if($API->hasErrors())
  throw_error('API inicialization error ('. implode('->', $API->getErrors()) .')' ,500);

//if(!$API->run()) throw_error('API run error '.$API->getError(),500); exit();

//$API->setPath( $_SERVER['DOCUMENT_ROOT'].'/lib/' );
//$API->setDBConf( $_SERVER['DOCUMENT_ROOT'].'/conf/db.user.php' );
//$API->router->setOptRules( '(token)=(tn(X|\w{32}))' );


$res=$API->invoke(
	'/register',
	'POST',
	array(
	  '_GET'=>array('token'=>'tn4bd3f406ab48c47b3e26e6e4033707b3'),
	  '_POST'=>array(
	    'u_worker'=>1,
	    
			'u_fname'=>'Петр',
			'u_mname'=>'Сергеевич',
			'u_lname'=>'Кукушкин',
			'u_email'=>'psk@gmail.com',
			'u_pwd'=>'psk@gmail.com',
			'u_country'=>'RU',
			'u_geo'=>array('ct705898712ceef6ca2de68bf8d7bfd1d0'),

			'p_url'=>'psk',
			'p_phone'=>'380678888888',
			'p_bdate'=>'1975-01-01',
			'p_gender'=>'m',
			'p_medicalBook'=>1,
		)
	)
);
if(!empty($res)){
  echo '<pre class="debug">'.print_r ( $res ,true).'</pre>'; exit();
}else
  echo '<pre class="debug">'.print_r ( $API->getError() ,true).'</pre>';


/*
include_once $_SERVER['DOCUMENT_ROOT'].'/lib/share.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/lib/Api.php';
$routes=include_once $_SERVER['DOCUMENT_ROOT'].'/conf/usr.router.php';

$apiUser=API::inst($routes);
$apiUser->setDBConf('/conf/db.user.php');
$apiUser->init();
//echo "Реализовать выдачу списка ошибочных полей при неудачной валидации модели";
$apiUser->run(); exit();

$r=$apiUser->invoke(
	'/register',
	'POST',
	array(
	  '_GET'=>array('token'=>'tn32991907d98b4f0f2d78d5a6b087335a'),
	  '_POST'=>array(
			'u_url'=>'test5',
			'u_fname'=>'test5',
			'u_mname'=>'test5',
			'u_lname'=>'test5',
			'u_email'=>'test5@geoshop.john.com.ua',
			'u_pwd'=>'test5@geoshop.john.com.ua',
			'u_country'=>array('UA'),
			'u_geo'=>array('ct705898712ceef6ca2de68bf8d7bfd1d0'),
			'u_country'=>'',

			'p_url'=>'test5',
			'p_phone'=>'380676665544',
			'p_bdate'=>'1985-01-01',
			'p_gender'=>'f',
			'p_medicalBook'=>1,
		)
	)
);
echo '<pre class="debug">'.print_r ( $r ,true).'</pre>';
*/
?>